package cassandrawindow;

/**
 * load config mysql 
 * @author datlt
 *
 */
public class PropertiesMysqlConfig extends PropertiesBase{

	public static String DRIVE = "com.mysql.jdbc.Driver";
	public static String HOST_DEFAULT = "hmaster87:3306" ;
	public static String DATABASE_DEFAULT = "websitestats";
	public static String USER_DEFAULT = "datlt";
	public static String PASSWORD_DEFAULT = "dat123456";
	
	public static String MYSQL_HOST="MYSQLHOST";
	public static String MYSQL_USER="MYSQLUSER";
	public static String MYSQL_PASSWORD="MYSQLPASS";
	public static String MYSQL_DATABASE="MYSQLDB";
	
	public PropertiesMysqlConfig(String _fileprop) {
		super(_fileprop);
	}
	/**
	 * Get host trong file property
	 * @return
	 */
	public String getMysqlHost(){
		return this.prop.getProperty(MYSQL_HOST.toUpperCase(), HOST_DEFAULT);
	}
	
	/**
	 * Get pass word trong file property
	 * @return
	 */
	public String getMysqlPass(){
		return this.prop.getProperty(MYSQL_PASSWORD.toUpperCase(), PASSWORD_DEFAULT );
	}
	
	/**
	 * Get Database trong file property
	 * @return
	 */
	public String getMysqlDatabase(){
		return this.prop.getProperty(MYSQL_DATABASE.toUpperCase(), DATABASE_DEFAULT);
	}

	/**
	 * Get Table trong file property
	 * @return
	 */
	public String getMysqlUser(){
		return this.prop.getProperty(MYSQL_USER, USER_DEFAULT);
	}
	
	public String getStringConnect(){
		String host=getMysqlHost();
		String dbname=getMysqlDatabase();
		String url = "jdbc:mysql://" + host + "/" + dbname+
		"?autoReconnect=true&useUnicode=true&characterEncoding=utf8" + "&zeroDateTimeBehavior=convertToNull";
		return url;
	}
	
	public static void main(String[] args){
		PropertiesMysqlConfig prop=new PropertiesMysqlConfig("properties/conf.properties");
		prop.loadFileProperties();
		System.out.println(prop.getStringConnect());
	}
}
